package dsm_ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import sound.AudioPlayer;
import store.storage;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MainGUI extends javax.swing.JFrame {

	private JButton Set_coord;
	private JMenuBar Menu;
	private JButton record_Button;
	private JButton stop_Button;
	private JButton play_button;
	private JPanel Sound_panel;
	private JMenuItem Save;
	private JMenuItem Open;
	private JMenuItem TestMix;
	private JPasswordField pinPassword;
	private JButton Remove;
	private JLabel namesLabel;
	private JLabel playlistLabel;
	private JLabel coordLabel;
	private JLabel pinLabel;
	private JComboBox<File> playListCombo;
	private JComboBox<storage> coordSelect;
	private JPanel main_Panel;
	private JMenu File_menu;
	private JButton coord_select;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainGUI inst = new MainGUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
				inst.getSet_coord().setPreferredSize(new java.awt.Dimension(150, 23));
				inst.setSize(385, 318);
			}
		});
	}
	
	public MainGUI() {
		super();
		initGUI();	//Initializes GUI
	}
	
	private void initGUI() 
	{
		try 
		{
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("Distributed Sound Mixer");
			{
				//Initialize a menubar
				Menu = new JMenuBar();
				setJMenuBar(Menu);
				{
					File_menu = new JMenu();
					Menu.add(File_menu);
					File_menu.setText("File");
					{
						Open = new JMenuItem();
						//set the open sub-menu
						File_menu.add(Open);
						Open.setText("Open");
					}
					{
						Save = new JMenuItem();
						//set the save sub-menu
						File_menu.add(Save);
						Save.setText("Save");
					}
					{
						TestMix = new JMenuItem();
						//set the save sub-menu
						File_menu.add(TestMix);
						TestMix.setText("Test Mixer");
					}
				}
			}
			
			{
				Sound_panel = new JPanel();
				getContentPane().add(Sound_panel, BorderLayout.SOUTH);
				Sound_panel.setPreferredSize(new java.awt.Dimension(300, 107));
				Sound_panel.setLayout(null);
				{
					play_button = new JButton();
					//add a play button
					Sound_panel.add(play_button);
					play_button.setText("Play");
					play_button.setBounds(15, 5, 80, 23);
				}
				{
					stop_Button = new JButton();
					//add stop button
					Sound_panel.add(stop_Button);
					stop_Button.setText("Stop");
					stop_Button.setBounds(102, 5, 80, 23);
				}
				{
					record_Button = new JButton();
					//add record button
					Sound_panel.add(record_Button);
					record_Button.setText("Record");
					record_Button.setBounds(190, 5, 80, 23);
				}
				{
					playListCombo = new JComboBox<File>();
					//add combo-box for playlist display
					Sound_panel.add(playListCombo);
					playListCombo.setBounds(90, 44, 260, 23);
				}
				{
					playlistLabel = new JLabel();
					Sound_panel.add(playlistLabel);
					playlistLabel.setText("Play List :");
					playlistLabel.setBounds(10, 47, 73, 16);
				}
				{
					namesLabel = new JLabel();
					Sound_panel.add(namesLabel);
					namesLabel.setText("By: Bibi, Janani, Yogeswar");
					namesLabel.setBounds(45, 80, 193, 16);
				}
				{
					Remove = new JButton();
					//add remove button
					Sound_panel.add(Remove);
					Remove.setText("Remove");
					Remove.setBounds(275, 5, 80, 23);
				}
			}
			{
				main_Panel = new JPanel();
				getContentPane().add(main_Panel, BorderLayout.CENTER);
				main_Panel.setLayout(null);
				{
					//ComboBoxModel coordSelectModel = new DefaultComboBoxModel(new String[] { "Waiting" });
					coordSelect = new JComboBox<storage>();
					main_Panel.add(coordSelect);
					//coordSelect.setModel(coordSelectModel);
					coordSelect.setBounds(90, 3, 260, 23);
				}
				{
					coord_select = new JButton();
					main_Panel.add(coord_select);
					coord_select.setText("Connect");
					coord_select.setBounds(172, 31, 99, 23);
				}
				{
					Set_coord = new JButton();
					//add 'set as coordinator' button
					main_Panel.add(Set_coord);
					Set_coord.setText("Set as Co-ordinator");
					Set_coord.setBounds(45, 68, 200, 23);
				}
				{
					pinPassword = new JPasswordField();
					main_Panel.add(pinPassword);
					pinPassword.setText("");
					pinPassword.setBounds(90, 31, 74, 23);
				}
				{
					pinLabel = new JLabel();
					main_Panel.add(pinLabel);
					//add a textbox to enter PIN
					pinLabel.setText("PIN : ");
					pinLabel.setBounds(10, 34, 51, 16);
				}
				{
					coordLabel = new JLabel();
					main_Panel.add(coordLabel);
					coordLabel.setText("Co-ordinators");
					coordLabel.setBounds(10, 6, 81, 16);
				}
			}
			pack();
			this.setSize(381, 271);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public JButton getSet_coord() {
		return Set_coord;
	}

	public void setSet_coord(JButton set_coord) {
		Set_coord = set_coord;
	}

	public JButton getRecord_Button() {
		return record_Button;
	}

	public void setRecord_Button(JButton record_Button) {
		this.record_Button = record_Button;
	}

	public JButton getStop_Button() {
		return stop_Button;
	}

	public void setStop_Button(JButton stop_Button) {
		this.stop_Button = stop_Button;
	}

	public JButton getPlay_button() {
		return play_button;
	}

	public void setPlay_button(JButton play_button) {
		this.play_button = play_button;
	}

	public JMenuItem getSave() {
		return Save;
	}

	public void setSave(JMenuItem save) {
		Save = save;
	}

	public JPasswordField getPinPassword() {
		return pinPassword;
	}

	public void setPinPassword(JPasswordField pinPassword) {
		this.pinPassword = pinPassword;
	}

	public JLabel getCoordLabel() {
		return coordLabel;
	}

	public void setCoordLabel(JLabel coordLabel) {
		this.coordLabel = coordLabel;
	}

	public JComboBox getPlayListCombo() {
		return playListCombo;
	}

	public void setPlayListCombo(JComboBox playListCombo) {
		this.playListCombo = playListCombo;
	}

	public JComboBox getCoordSelect() {
		return coordSelect;
	}

	public void setCoordSelect(JComboBox coordSelect) {
		this.coordSelect = coordSelect;
	}

	public JButton getCoord_select() {
		return coord_select;
	}

	public void setCoord_select(JButton coord_select) {
		this.coord_select = coord_select;
	}

	public JMenuItem getOpen() {
		return this.Open;
	}

	public void setOpen(JMenuItem open) {
		Open = open;
	}

	public void addPlayListener(ActionListener al)
	{
		this.play_button.addActionListener(al);
	}
	
	public void addOpenListener(ActionListener al)
	{
		this.Open.addActionListener(al);
	}
	
	public void addStopListener(ActionListener al)
	{
		this.stop_Button.addActionListener(al);
	}
	
	public void addRecordListener(ActionListener al)
	{
		this.record_Button.addActionListener(al);
	}
	
	public void addSetCoordListener(ActionListener al)
	{
		this.Set_coord.addActionListener(al);
	}
	
	public void addCoordSelectListener(ActionListener al)
	{
		this.coord_select.addActionListener(al);
	}
	
	public void addSaveListener(ActionListener al)
	{
		this.Save.addActionListener(al);
	}
	
	public void addWindowCloseListener(WindowListener wa)
	{
		addWindowListener(wa);
	}
	
	public void addRemoveListener(ActionListener al)
	{
		this.Remove.addActionListener(al);
	}
	
	public void addTestMixListener(ActionListener al)
	{
		this.TestMix.addActionListener(al);
	}
	
	public void setCoordList(List<storage> coordList)
	{
		storage Coordarray[] = coordList.toArray(new storage[coordList.size()]);
		ComboBoxModel<storage> coordSelectModel = new DefaultComboBoxModel<storage>(Coordarray);
		this.coordSelect.setModel(coordSelectModel);
	}
	
	public void setPlayList(List<File> Coord)
	{
		File files[] = Coord.toArray(new File[Coord.size()]);
		ComboBoxModel<File> coordSelectModel = new DefaultComboBoxModel<File>(files);
		this.playListCombo.setModel(coordSelectModel);
	}
	
	public Object getSelectedCoord()
	{
		return this.coordSelect.getSelectedItem();
	}
	
	public Object getSelectedFile()
	{
		return this.playListCombo.getSelectedItem();
	}
	
	public int getSelectedFileIndex()
	{
		return this.playListCombo.getSelectedIndex();
	}
	
	public void removeSelectedFile(Object f)
	{
		this.playListCombo.removeItem(f);
	}
	
	public void setSelectedCoord(File s1)
	{
		this.coordSelect.setSelectedItem(s1);
	}
	
	public void setSelectedFile(File s1)
	{
		this.playListCombo.setSelectedItem(s1);
	}
	
	public void addFile(File s1)
	{
		this.playListCombo.addItem(s1);
	}
	
	public String getPIN()
	{
		return this.pinPassword.getText();
	}
	
	public void changecoord_select(boolean status)
	{
		this.coord_select.setEnabled(status);
	}
	
	public void changecoordSelect(boolean status)
	{
		this.coordSelect.setEnabled(status);
	}
	
	public void changeOpen(boolean status)
	{
		this.Open.setEnabled(status);
	}
	
	public void changeplay_button(boolean status)
	{
		this.play_button.setEnabled(status);
	}
	
	public void changeplayListCombo(boolean status)
	{
		this.playListCombo.setEnabled(status);
	}
	
	public void changeRecord(boolean status)
	{
		this.record_Button.setEnabled(status);
	}
	
	public void changeRemove(boolean status)
	{
		this.Remove.setEnabled(status);
	}
	
	public void changeSave(boolean status)
	{
		this.Save.setEnabled(status);
	}
	
	public void changeSetCoord(boolean status)
	{
		this.Set_coord.setEnabled(status);
	}
	
	public void changeStop(boolean status)
	{
		this.stop_Button.setEnabled(status);
	}
	
	public void changeTestMix(boolean status)
	{
		this.TestMix.setEnabled(status);
	}
}
